home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-27 | 4.1 KB | 157 lines | [TEXT/CWIE] |
- //
- // CQD3DErrorsDoc.cp
- //
- // class CQD3DErrorsDoc
- // Send QuickDraw 3D errors to a TextEdit window.
- //
- // by James Jennings
- // November 23, 1995
- //
-
- #include "CQD3DErrorsDoc.h"
- #include "QD3D Debug Macros.h"
-
- #include <LTextEdit.h>
-
- const PaneIDT PaneID_TextPane = 9999;
- const ResIDT WIND_ErrorsDoc = 9997;
-
- // This is a "singleton" class: There can only be one of them, and that
- // instance is stored in the class variable "singleton".
- CQD3DErrorsDoc *CQD3DErrorsDoc::singleton = 0;
-
-
- CQD3DErrorsDoc::CQD3DErrorsDoc()
- {
- ThrowIf_(singleton!=0); // we can't make more than one of these
-
- // Create window for our document
- mWindow = LWindow::CreateWindow(WIND_ErrorsDoc, this);
-
- // Specify that the text view should
- // be the Target when the Window
- // is activated
- LTextEdit *pane = (LTextEdit*)mWindow->FindPaneByID(PaneID_TextPane);
- ThrowIfNil_ (pane);
- // SetLatentPane() gives an error: I don't know why.
- // mWindow->SetLatentSub(pane);// assign sub-commander
-
- // Remember the TE pane that we'll be writing to.
- mTE = pane->GetMacTEH();
- ThrowIfNil_ (mTE);
-
- // register our error handlers
- TQ3Status status;
- status = ::Q3Error_Register(ErrorMethod, 0);
- ThrowIfQ3Fail_(status);
- status = ::Q3Warning_Register(WarningMethod, 0);
- ThrowIfQ3Fail_(status);
- status = ::Q3Notice_Register(NoticeMethod, 0);
- ThrowIfQ3Fail_(status);
-
- // make sure we can find this later
- singleton = this;
- }
-
- CQD3DErrorsDoc::~CQD3DErrorsDoc()
- {
-
- }
-
- //
- // Error handling functions. [static]
- //
- void
- CQD3DErrorsDoc::ErrorMethod( TQ3Error first, TQ3Error last, long reference)
- {
- TQ3Error dummy;
- OSErr fst, lst;
- CQD3DErrorsDoc *theDoc = CQD3DErrorsDoc::GetInstance();
- if (theDoc) {
- if (Q3Error_IsFatalError(first)) {
- theDoc->Common("\pFATAL ERROR", (long)first, (long)last);
- if (first==kQ3ErrorMacintoshError) {
- fst = ::Q3MacintoshError_Get(&lst);
- theDoc->Common("\pFatal Macintosh Error was", (long)fst, (long)lst);
- }
- } else {
- theDoc->Common("\pError", (long)first, (long)last);
- if (first==kQ3ErrorMacintoshError) {
- fst = ::Q3MacintoshError_Get(&lst);
- theDoc->Common("\pMacintosh Error was", (long)fst, (long)lst);
- }
- }
- /* This clears the sticky error */
- ::Q3Error_Get(&dummy);
- }
- }
-
- void
- CQD3DErrorsDoc::WarningMethod(TQ3Warning first, TQ3Warning last, long reference)
- {
- CQD3DErrorsDoc *theDoc = CQD3DErrorsDoc::GetInstance();
- if (theDoc) {
- theDoc->Common("\pWarning", (long)first, (long)last);
- }
- }
-
- void
- CQD3DErrorsDoc::NoticeMethod( TQ3Notice first, TQ3Notice last, long reference)
- {
- CQD3DErrorsDoc *theDoc = CQD3DErrorsDoc::GetInstance();
- if (theDoc) {
- theDoc->Common("\pNotice", (long)first, (long)last);
- }
- }
-
- //
- // Common error handling function
- //
- static void // helper function
- DoErrorText(TEHandle hTE, StringPtr type, long err)
- {
- const Str63 del = "\p: "; // standard delimeter
- Str63 num;
- ::TEInsert(type+1, *type, hTE); // write Error/Warning/Notice
- ::TEInsert(del+1, *del, hTE); // write delimeter
- ::NumToString(err, num);
- ::TEInsert(num+1, *num, hTE); // write error number
- // Get error string and insert it here
- if (short(err) == err) {
- // it's a short error: look up the name in a resource
- ::TEInsert(del+1, *del, hTE); // write delimeter
- StResource str('Estr', err, false); // don't throw if failed
- if (str.mResourceH) {
- StHandleLocker strLock(str);
- ::TEKey('“', hTE);
- ::TEInsert(*(str.mResourceH)+1, **(str.mResourceH), hTE);
- ::TEKey('”', hTE);
- } else {
- Str63 unknown = "\p(no error desc)";
- ::TEInsert(unknown+1, *unknown, hTE); // write delimeter
- }
- } else {
- // it's a long error: Do nothing.
- // ::TEInsert(&err, 4, hTE);
- }
- }
- // end helper function
- Boolean
- CQD3DErrorsDoc::Common(StringPtr type, long first, long last)
- {
- mWindow->Show(); // window is hidden until the first error
-
- Int16 teLength = (**mTE).teLength;
- ::TESetSelect(teLength, teLength, mTE); // move insertion to the end
-
- DoErrorText(mTE, type, first);
-
- if (last != 0) { // if it's not kQ3ErrorNone, kQ3WarningeNone, or kQ3NoticeNone
- const Str63 lst = "\p: Last ";
- ::TEInsert(lst+1, *lst, mTE); // write "Last "
- DoErrorText(mTE, type, last);
- }
- TEKey('\r', mTE); // write newline
- return true;
- }
-